/**********************************************************
 *   Author          : Apriluestc
 *   Email           : 13669186256@163.com
 *   Last modified   : 2019-07-28 13:30
 *   Filename        : Thread.h
 *   Description     : 
 * *******************************************************/

#ifndef INCLUDE_THREAD_H
#define INCLUDE_THREAD_H

#include <functional>
#include <memory>
#include <pthread.h>
#include <string>
#include <sys/syscall.h>
#include <unistd.h>
#include <boost/noncopyable.hpp>

#include "CountDownLatch.h"

class Thread : boost::noncopyable {
public:
    typedef std::function<void ()> ThreadFunc;
    explicit Thread(const ThreadFunc&, const std::string& name = std::string());
    ~Thread();
    void start();
    int join();
    bool started() const {
        return started_;
    }
    pid_t tid() const {
        return tid_;
    }
    const std::string& name() const {
        return name_;
    }

private:
    void setDefaultName();
    bool started_;
    bool joined_;
    pthread_t pthreadId_;
    pid_t tid_;
    ThreadFunc func_;
    std::string name_;
    CountDownLatch latch_;
}; // Thread

#endif // INCLUDE_THREAD_H
